package insight.google.game.era.data;

import insight.google.game.era.bo.GameRoom;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Order;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.RemoteProperty;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@DataTransferObject
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class GameHistory extends BaseData {

//	@RemoteProperty
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@PrimaryKey
	private Key id;

	@RemoteProperty
	@Persistent
	private String roomId;

	@RemoteProperty
	@Persistent
	private String ownerId;

	@RemoteProperty
	@Persistent
	private int noOfUsers;

	@RemoteProperty
	@Persistent
	private Date startTime = new Date();

	@RemoteProperty
	@Persistent
	private Date endTime;

	@RemoteProperty
	@Persistent
	private int status;
	
	@RemoteProperty
	@Persistent
	private String roomName;

	@RemoteProperty
	@Persistent(mappedBy = "gameHistory",defaultFetchGroup="true")
	private List<GameHistoryDetail> gameHistoryDetailList = new ArrayList<GameHistoryDetail>();

	public GameHistory() {

	}

	public Key getId() {
		return id;
	}

	public void setId(Key id) {
		this.id = id;
	}

	public String getRoomId() {
		return roomId;
	}

	public void setRoomId(String roomId) {
		this.roomId = roomId;
	}

	public String getOwnerId() {
		return ownerId;
	}

	public void setOwnerId(String userId) {
		this.ownerId = userId;
	}

	public int getNoOfUsers() {
		return noOfUsers;
	}

	public void setNoOfUsers(int noOfUsers) {
		this.noOfUsers = noOfUsers;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public List<GameHistoryDetail> getGameHistoryDetailList() {
		return gameHistoryDetailList;
	}

	public void setGameHistoryDetailList(
			List<GameHistoryDetail> gameHistoryDetailList) {
		this.gameHistoryDetailList = gameHistoryDetailList;
	}

	public void addGameUserHistory(GameHistoryDetail gameUserHistoryJDO) {
		if (this.gameHistoryDetailList.contains(gameUserHistoryJDO)) {
			// this.gameUserHistoryJdoList.remove(gameUserHistoryJDO);
		}
		this.gameHistoryDetailList.add(gameUserHistoryJDO);
	}
	
	

	public String getRoomName() {
		return roomName;
	}

	public void setRoomName(String roomName) {
		this.roomName = roomName;
	}

	@RemoteProperty
	public String getHistoryId() {
		return KeyFactory.keyToString(id);
	}

	// public GameRoomJDO getGameRoom() {
	// return gameRoom;
	// }
	//
	// public void setGameRoom(GameRoomJDO gameRoom) {
	// this.gameRoom = gameRoom;
	// }

}
